package com.atguigu.ssyx.product.controller;

import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.product.Category;
import com.atguigu.ssyx.product.service.CategoryService;
import com.atguigu.ssyx.vo.product.CategoryQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杨林
 * @create 2023-07-19 10:42 星期三
 * description:
 */

/**
 * 商品管理
 */
@Api(value = "Category管理",tags = "商品分类管理")
@RestController
@RequestMapping("/admin/product/category")
@CrossOrigin   //跨域
public class CategoryController {
    
    @Autowired
    private CategoryService categoryService;

    /**
     * 分页查询商品列表
     * @return
     */
    @ApiOperation(value = "分页查询商品列表")
    @GetMapping("/{page}/{limit}")
    public Result getPageList(@PathVariable("page") Long page,
                              @PathVariable("limit") Long limit,
                              CategoryQueryVo categoryQueryVo){
       IPage pageModel = categoryService.getPageList(page,limit,categoryQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * 根据商品Id查找商品
     * @return
     */
    @ApiOperation(value = "根据商品id查询商品")
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable("id") Long id){
        Category category = categoryService.getById(id);
        return Result.ok(category);
    }

    /**
     * 保存商品
     * @return
     */
    @ApiOperation(value = "保存商品")
    @PostMapping("/save")
    public Result save(@RequestBody Category category){
        categoryService.save(category);
        return Result.ok();
    }


    /**
     * 根据id更新商品信息
     * @return
     */
    @ApiOperation(value = "根据id更新商品信息")
    @PutMapping("/update")
    public Result updateById(@RequestBody Category category){
        categoryService.updateById(category);
        return Result.ok();
    }

    /**
     * 根据商品Id删除商品信息
     * @return
     */
    @ApiOperation(value = "根据商品id删除商品信息")
    @DeleteMapping("/remove/{id}")
    public Result removeById(@PathVariable("id") Long id){
        categoryService.removeById(id);
        return Result.ok();
    }


    /**
     * 根据ids批量删除商品信息
     * @return
     */
    @ApiOperation(value = "根据ids批量删除商品信息")
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<Long> ids){
        System.out.println(ids);
        return Result.ok();
    }

    /**
     * 查询所有的商品信息
     * @return
     */
    @ApiOperation(value = "查询所有的商品信息")
    @GetMapping("/findAllList")
    public Result findAllList(){
        List<Category> list = categoryService.findAllList();
        return Result.ok(list);
    }
}
